<?php
declare (strict_types=1);

namespace app\admin\controller;


use app\common\facade\Builder;

use think\App;
use think\facade\View;
use think\response\Json;

class Mechanism extends Base
{

    //主键，默认为id
    protected string $pk = 'id';

    //主模型
    protected string $model = '\app\common\model\Mechanism';


    //关联模型
    protected array $hasOne = ['user'];

    public function index(): string
    {
        //构建table
        return Builder::Table()
//            ->addColumn(['type' => 'checkbox', 'fixed' => 'left', 'field' => '', 'title' => '全选'])
            ->addColumn(['field' => 'id', 'sort' => true, 'title' => 'ID', 'width' => 80])
            ->addColumn(['field' => 'code', 'title' => '会员信息', 'templet' => '#_userTpl', 'width' => 250])
            ->addColumn(['field' => 'title', 'title' => '机构名称', 'modify' => '2,input'])
            ->addColumn(['field' => 'disseminate', 'title' => '机构宣传', 'modify' => '2,input'])
            ->addColumn(['field' => 'address', 'title' => '机构地址', 'modify' => '2,input'])
            ->addColumn(['field' => 'award_information', 'title' => '获奖信息', 'modify' => '2,input'])
            ->addColumn(['field' => 'trainees_number', 'title' => '学员人数', 'modify' => '2,input'])
            ->addColumn(['field' => 'teacher_number', 'title' => '教师人数', 'modify' => '2,input'])
            ->addColumn(['field' => 'create_time', 'title' => '创建时间'])
            ->addColumn(['field' => 'update_time', 'title' => '更新时间'])
            ->addColumn(['field' => 'status', 'title' => '状态'])
            ->addColumn(['field' => 'admin_name', 'title' => '审核人'])
            ->addColumn(['field' => 'confirm_time', 'title' => '审核时间'])
            ->addColumn(['fixed' => 'right', 'align' => 'center', 'toolbar' => '#barDemo', 'title' => '操作', 'width' => 100])
            ->addRightButtons(['edit' => ['title' => '审核', 'size' => '1000,1000']])
            ->addSwitchTool()
            ->addSortTool()
            ->addSearch([
                ['title', '输入机构名称 ', 'input', '', '', '', 'like'],
            ])
            ->fetch();
    }


    public function add($tpl = 'mechanism/edit'): string
    {
        return parent::add($tpl); // TODO: Change the autogenerated stub
    }

    public function edit($id = '', $tpl = 'mechanism/edit', $info = ''): string
    {
        return parent::edit($id, $tpl, $info); // TODO: Change the autogenerated stub
    }


    public function save($param = [], $model = true): Json
    {
        try {
            $param = $this->request->post();
//            dump($param);die;
            return parent::save($param, $model); // TODO: Change the autogenerated stub
        } catch (\Exception $e) {
            dump($e->getMessage());die;

        }
    }


}
